package SquarePackage;

import static org.junit.Assert.*;

import java.math.BigDecimal;

import org.junit.*;
import Border.Door;
import Border.Wall;

public class RockTest {
    private NormalSquare testNormalSquare2;
	private NormalSquare testNormalSquare;
	private Rock testRock2;
	private Rock testRock3;
	private Rock testRock4;
	private Rock testRock5;
    public Rock testRock;
	private Wall testWall;
	private Wall testWall2;
	private Door testDoor;
	private Wall testWall3;
	private Wall testWall4;
	private TeleportableSquare testNormalSquare3;
	private Wall testWall5;
	/**
     * @throws java.lang.Exception
     */
	private TeleportableSquare testNormalSquare4;
    @Before
    public void setUp() throws Exception {
            testRock = new Rock();
            testRock2 = new Rock();
        	testRock3 = new Rock();
        	testRock4 = new Rock();
        	testRock5 = new Rock();
    		testNormalSquare = new NormalSquare(200, new BigDecimal(20));
    		testNormalSquare2 =  new NormalSquare(100, new BigDecimal(60));
    		testNormalSquare3 =  new NormalSquare(150, new BigDecimal(60));
    		testNormalSquare4 = new NormalSquare(600, BigDecimal.ZERO);
    }
    @Test
    public final void constructor(){
            assertEquals(6, testRock.numberOfBorders());
            assertEquals(0, testRock.getTemperature().getTemperature(),0);
            assertEquals(new BigDecimal("0"),testRock.getHumidity());
    }
    
    @Test
    public final void isValidHumidity0(){
            assertTrue(testRock.isValidHumidity(new BigDecimal("0")));
            assertTrue(testRock.isValidHumidity(new BigDecimal("0.00")));
            assertFalse(testRock.isValidHumidity(new BigDecimal("28")));
            assertFalse(testRock.isValidHumidity(new BigDecimal("-28")));
            assertFalse(testRock.isValidHumidity(null));
    }

    @Test
    public void CalculateTemperatureTest(){
    	testWall = (Wall) testRock.getBorderAt(Direction.WEST);
    	testRock2.replaceBorderWith((Wall)testRock2.getBorderAt(Direction.EAST), testWall);
    	testWall.setSquare(testRock2);
    	testRock2.updateTemperature();
    	testRock.updateTemperature();
    	assertEquals(0, testRock2.getTemp(),0.01);
    	assertEquals(0, testRock.getTemp(),0.01);
    	testWall2 = (Wall) testRock2.getBorderAt(Direction.NORTH);
    	testNormalSquare.setBorder(Direction.SOUTH, testWall2);
    	testRock.updateTemperature();
    	testRock2.updateTemperature();
    	assertEquals(200, testRock.getTemp(),0.01);
    	assertEquals(200, testRock2.getTemp(),0.01);
    	testWall3 = (Wall) testRock.getBorderAt(Direction.EAST);
    	testNormalSquare2.setBorder(Direction.WEST, testWall3);
    	testRock.updateTemperature();
    	testRock2.updateTemperature();
    	assertEquals(133, testRock.getTemp(),1);
    	assertEquals(166, testRock2.getTemp(),1);
    	testWall4 = (Wall)testRock2.getBorderAt(Direction.WEST);
    	testNormalSquare3.setBorder(Direction.EAST,testWall4);
    	testRock.updateTemperature();
    	testRock2.updateTemperature();
    	assertEquals(130, testRock.getTemp(),1);
    	assertEquals(160, testRock2.getTemp(),1);
    	testWall5 = (Wall)testRock2.getBorderAt(Direction.CEILING);
    	testNormalSquare4.setBorder(Direction.CEILING, new Wall(testNormalSquare4,Direction.CEILING));
    	testNormalSquare4.removeBorder(Direction.FLOOR);
    	testNormalSquare4.setBorder(Direction.FLOOR, testWall5);
    	testRock.updateTemperature();
    	testRock2.updateTemperature();
    	assertEquals(192, testRock.getTemp(),1);
    	assertEquals(285, testRock2.getTemp(),1);
    	
    	
    }


}
